﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace MediaRegister
{

    public partial class FormRepData : Form
    {
        private struct repData
        {
            public string Nr;
            public string KundNamn;
            public string TellNr;
            public string Objekt;
            public string Fel;
        }



        public FormRepData()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            repData repd;
            repd.Nr = textBox1.Text;
            repd.KundNamn = textBox2.Text;
            repd.TellNr= textBox3.Text;
            repd.Objekt = textBox4.Text;
            repd.Fel = textBox5.Text;
            FileStream fs2 = new FileStream(@"M:RepData.txt", FileMode.Append, FileAccess.Write);
            StreamWriter sr2 = new StreamWriter(fs2);
            sr2.WriteLine(repd.Nr + " , " + repd.KundNamn + " , " + repd.TellNr + " , " + repd.Objekt + " , " + repd.Fel);
            foreach (Control t in this.Controls)
                if (t is TextBox)
                    t.Text = " ";
            sr2.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            String s2;
            if (File.Exists(@"M:RepData.txt"))
            {
                FileStream fs2 = new FileStream(@"M:\RepData.txt", FileMode.Open, FileAccess.Read);
                StreamReader sr2 = new StreamReader(fs2);
                s2 = sr2.ReadLine();
                while (s2 != null)
                {
                    listBox1.Items.Add(s2);
                    s2 = sr2.ReadLine();


                }
                sr2.Close();
            }

            else
            {
                MessageBox.Show("Finns ingen fil att visa");
            }



        }
    }

    }

